<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Parse a document stored in a string</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="tidy.parsefile.html">tidy::parseFile</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="tidy.repairfile.html">tidy::repairFile</a></div>
 <div class="up"><a href="class.tidy.html">tidy</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="tidy.parsestring" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">tidy::parseString</h1>
  <h1 class="refname">tidy_parse_string</h1>
  <p class="verinfo">(PHP 5, PECL tidy &gt;= 0.5.2)</p><p class="refpurpose"><span class="refname">tidy::parseString</span> -- <span class="refname">tidy_parse_string</span> &mdash; <span class="dc-title">Parse a document stored in a string</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-tidy.parsestring-description">
  <h3 class="title">说明</h3>
  <p class="para">面向对象风格</p>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>tidy::parseString</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$input</code></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$config</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$encoding</code></span>
  ]] )</div>

  <p class="para rdfs-comment">过程化风格</p>
  <div class="methodsynopsis dc-description">
   <span class="type"><a href="class.tidy.html" class="type tidy">tidy</a></span> <span class="methodname"><strong>tidy_parse_string</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$input</code></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$config</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$encoding</code></span>
  ]] )</div>

  <p class="para rdfs-comment">
   Parses a document stored in a string.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-tidy.parsestring-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">input</code></em></dt>

     <dd>

      <p class="para">
       The data to be parsed.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">config</code></em></dt>

     <dd>

      <p class="para">
       The config <em><code class="parameter">config</code></em> can be passed either as an
       array or as a string. If a string is passed, it is interpreted as the
       name of the configuration file, otherwise, it is interpreted as the
       options themselves.
      </p>
      <p class="para">
       For an explanation about each option, visit <a href="http://tidy.sourceforge.net/docs/quickref.html" class="link external">&raquo;&nbsp;http://tidy.sourceforge.net/docs/quickref.html</a>.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">encoding</code></em></dt>

     <dd>

      <p class="para">
       The <em><code class="parameter">encoding</code></em> parameter sets the encoding for
       input/output documents. The possible values for encoding  are: 
       <em>ascii</em>, <em>latin0</em>, <em>latin1</em>,
       <em>raw</em>, <em>utf8</em>, <em>iso2022</em>,
       <em>mac</em>, <em>win1252</em>, <em>ibm858</em>,
       <em>utf16</em>, <em>utf16le</em>, <em>utf16be</em>,
       <em>big5</em>, and <em>shiftjis</em>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-tidy.parsestring-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a new <a href="class.tidy.html" class="classname">tidy</a> instance.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-tidy.parsestring-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3961">
    <p><strong>Example #1 <span class="function"><strong>tidy::parseString()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />ob_start</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;<br /></span><br />&lt;html&gt;<br />&nbsp;&nbsp;&lt;head&gt;<br />&nbsp;&nbsp;&nbsp;&lt;title&gt;test&lt;/title&gt;<br />&nbsp;&nbsp;&lt;/head&gt;<br />&nbsp;&nbsp;&lt;body&gt;<br />&nbsp;&nbsp;&nbsp;&lt;p&gt;error&lt;br&gt;another&nbsp;line&lt;/i&gt;<br />&nbsp;&nbsp;&lt;/body&gt;<br />&lt;/html&gt;<br /><br /><span style="color: #0000BB">&lt;?php<br /><br />$buffer&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ob_get_clean</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$config&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'indent'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">TRUE</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'output-xhtml'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">TRUE</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'wrap'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">200</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$tidy&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">tidy_parse_string</span><span style="color: #007700">(</span><span style="color: #0000BB">$buffer</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$config</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'UTF8'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$tidy</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">cleanRepair</span><span style="color: #007700">();<br />echo&nbsp;</span><span style="color: #0000BB">$tidy</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;
    &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
  &lt;head&gt;
    &lt;title&gt;
      test
    &lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;p&gt;
      error&lt;br /&gt;
      another line
    &lt;/p&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-tidy.parsestring-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">可选参数
<em><code class="parameter">config</code></em> 和 <em><code class="parameter">encoding</code></em> 是在
Tidy 2.0 中加入的。</span></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-tidy.parsestring-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="function"><a href="tidy.parsefile.html" class="function" rel="rdfs-seeAlso">tidy::parseFile()</a> - Parse markup in file or URI</span></li>
   <li class="member"><span class="function"><a href="tidy.repairfile.html" class="function" rel="rdfs-seeAlso">tidy::repairFile()</a> - Repair a file and return it as a string</span></li>
   <li class="member"><span class="function"><a href="tidy.repairstring.html" class="function" rel="rdfs-seeAlso">tidy::repairString()</a> - Repair a string using an optionally provided configuration file</span></li>
  </ul>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="tidy.parsefile.html">tidy::parseFile</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="tidy.repairfile.html">tidy::repairFile</a></div>
 <div class="up"><a href="class.tidy.html">tidy</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
